import request from "../../utils/http";
import { anyObj, enter } from "../../utils/util";

// pages/payOrderSuccess/payOrderSuccess.ts
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		query: <anyObj>{},
		order: {
			orderNo: '',
			createdTime: '',
			serviceName: '',
			totalPrice: 0
		}
	},

	/**
	 * 点击预约
	 */
	async submit() {
		let urlName = 'reservationFirst';
		try {
			const data = await request({
				url: '/api/customers/reservation/getAddressAndFamilyMember',
				method: 'GET'
			});
			if (data) {
				urlName = 'reservationPro';
			}
			enter({
				url: `/pages/${urlName}/${urlName}`,
				original: wx.redirectTo,
				query: this.data.query
			});
		} catch (error) {
			
		}
	},

	async getOrder() {
		try {
			const order = await request({
				url: '/api/customers/order/getAppointmentOrder',
				method: 'GET',
				errToast: true
			});
			this.setData({
				order: {
					orderNo: order.orderNo,
					createdTime: order.createdTime,
					serviceName: order.servicesVo?.name || '',
					totalPrice: order.totalPrice
				}
			});
		} catch (error) {
			
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(query = {}) {
		this.setData({query});
		if (this.data.query.orderId) {
			this.getOrder();
		} else {
			wx.showToast({title: '没有订单 ID', icon: 'error'});
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})